#!/bin/sh

if [ "$#" -lt 2 ]; then
	echo "Usage: $0 server_addr image"
	exit 1
fi

IP=$1
IMG=$2

TDIR=.tmp_dir
rm -fr $TDIR
mkdir -p $TDIR
cd $TDIR

echo "get image from $IP"
ftpget $IP $IMG
if [ $? -eq "0" ]; then
	echo "get image from $IP done"
else
	echo "get image from $IP error"
	exit 1
fi

mkdir -p boot sys triones conf
mount /dev/sda1 boot
mount /dev/sda2 sys
mount /dev/sda3 triones
mount /dev/sda5 conf

echo "extract image"
#extract.sh $IMG
tar xf $IMG
echo "extract image done"

echo "install kernel"
mkdir -p boot/ntsec/
mv bzImage boot/ntsec/vmlinuz
mv firewall.gz boot/ntsec/initrd.gz
echo "install kernel done"

echo "install firewall"
tar zxf triones.tgz
echo "install firewall done"


umount /dev/sda1
umount /dev/sda2
umount /dev/sda3
umount /dev/sda5
